package com.diyunapp.xilinapp.fragments;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.diyunapp.xilinapp.R;
import com.diyunapp.xilinapp.details.GoodsDetailActivity;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by NIDAYE on 2016/6/20.
 */
public class GoodDetailInfoFragment extends Fragment {

    @Bind(R.id.good_detailinfo_wv)
    WebView goodDetailinfoWv;
    private View myFragmentView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        myFragmentView = inflater.inflate(R.layout.good_detailinfo_fragment, null);
        ButterKnife.bind(this, myFragmentView);
        loadDetail();
        return myFragmentView;
    }

    private void loadDetail() {
        //启用支持javascript
        WebSettings settings = goodDetailinfoWv.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setSupportZoom(false);
        settings.setDomStorageEnabled(true);
        settings.setLoadWithOverviewMode(true);

        goodDetailinfoWv.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });

        String url = "http://www.xilingou.com/wap/tmpl/product_info.html?goods_id=" + GoodsDetailActivity.good_id;
        goodDetailinfoWv.loadUrl(url);

        Log.i("zhangxiaoxidebug","url="+url);
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
